/**
 * @(#)clienteSocketL.java
 *
 *
 * @author 
 * @version 1.00 2009/5/7
 */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class clienteSocketL extends MIDlet{
	
	private miWaitScreen wait_screen;
	private formularioP form_principal;
	private socketConexion conexion;
	private Display display;
	
    public clienteSocketL() {
    	//recogemos el objeto display
    	display=display.getDisplay(this);
    }
    
    public void startApp()throws MIDletStateChangeException{
    	wait_screen=new miWaitScreen();
    	opcionDisplayable(null,wait_screen);
   	    conexion=new socketConexion(this);
    	conexion.start();
    }

    
    public void setForm_principal(String titulo){
         wait_screen.finHilo();
         opcionDisplayable(null,form_principal=new formularioP(this,titulo,conexion));
    }
    
    public void setTexto_form(String texto){
    	form_principal.setTexto(texto);
    }
	
	public void setTitle_form(String texto){
    	form_principal.setTitle(texto);
    }
    
    public void controlComandos(int opcion){
    	switch(opcion){
    		case 0:{form_principal.quitaComando_enviar();break;}
    		case 1:{form_principal.regresaComando_enviar();break;}	
    	}
    }
    
    public void mustraAlerta_exit(){
    	Alert a = new Alert( "Cliente", "Debes lanzar el Servidor en primer lugar.",null,AlertType.ERROR );
        a.setTimeout(4000);
        display.setCurrent( a );
    	exitMIDlet();
    }
	
	public void exitMIDlet(){
		destroyApp(false);
		notifyDestroyed();
	}

    
	public void opcionDisplayable(Alert alert,Displayable d){
		if(alert==null) display.setCurrent(d);
		else display.setCurrent(alert,d);
	}
	
    
    public void pauseApp(){}
	
    public void destroyApp(boolean incondicional){}
    
	
}
